using Data.Domain;
using Data.Repositories;
using NUnit.Framework;
using Tests.Specs.BaseClasses;
using Web.Controllers;

namespace Tests.Specs.ControllerSpecs
{
    [Category("HomeControllerSpecs")]
    public class BaseHomeControllerSpecs : SpecificationsFor<HomeController>
    {
        protected IRepository<Player> playerRepository;

        public override void Set_up_context()
        {
            base.Set_up_context();

            // Set up dependencies
            playerRepository = AMockedDependencyOfType<IRepository<Player>>();
        }

        public override void And_calling()
        {
            throw new System.NotImplementedException();
        }
    }

    [TestFixture]
    public class When_viewing_the_index_page : BaseHomeControllerSpecs
    {
        public override void And_calling()
        {
            sut.Index();
        }

        [Test]
        public void Should_call_the_repository_to_retrieve_all_players()
        {
            playerRepository.WasCalled(x => x.GetAll());
        }
    }

    [TestFixture]
    public class When_editing_a_player : BaseHomeControllerSpecs
    {
        private int id;

        public override void Set_up_context()
        {
            base.Set_up_context();

            id = 2;
        }

        public override void And_calling()
        {
            sut.Edit(id);
        }

        [Test]
        public void Should_load_the_player_by_the_given_id()
        {
            playerRepository.WasCalled(x => x.GetById(id));
        }
    }

    [TestFixture]
    public class When_updating_a_player : BaseHomeControllerSpecs
    {
        private int id;

        public override void Set_up_context()
        {
            base.Set_up_context();

            // Set up an id and a non-null player returned
            id = 21;
            WhenThe(playerRepository).IsToldTo(x => x.GetById(id)).Return(new Player());
        }

        public override void And_calling()
        {
            sut.UpdatePlayer(id);
        }

        [Test]
        public void Should_get_the_player_by_the_given_id()
        {
            playerRepository.WasCalled(x => x.GetById(id));
        }
    }
}